<template>
  <!--公文管理特色处理，非通用版--->
  <div>
    <el-form-item v-if="showDesc" label="审批意见" :label-width="formlabelWidth">
      <input-description v-model="form.description"></input-description>
    </el-form-item>
    <el-form-item  v-if="this.entity.status==0" label="送其他部门负责人" :label-width="formlabelWidth">
      <el-radio-group v-model="form.sendOtherLeader" @input="changeFormValue">
        <el-radio :label="1">是</el-radio>
        <el-radio :label="2">否</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item  v-if="entity.taskKey=='UserTask_0giw23k'" label="是否送阅件人员" :label-width="formlabelWidth">
      <el-radio-group v-model="form.isRead">
        <el-radio :label="1">是</el-radio>
        <el-radio :label="2">否</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item  v-if="entity.taskKey=='UserTask_0m5jq6b'" label="分管副总确认办件部门" :label-width="formlabelWidth">
      <el-radio-group v-model="form.leaderConfirm" @input="changeFormValue">
        <el-radio :label="2">是</el-radio>
        <el-radio :label="1">否</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item v-show="isShow||showUserSelect" :required="showUserSelect" label="处理人" :label-width="formlabelWidth">
      <select-assignee ref="selectAssignee" v-model="form.selectAssigneeList" :multiple="multiple"
                       :data="wfNode.nextUserList"></select-assignee>
    </el-form-item>
  </div>
</template>

<script>
  import wfStatusMixin from '@/mixins/wfStatusMixin'

  export default {
    name: "bpmn-form",
    components: {
      SelectAssignee: () => import('./select-assignee'),
      InputDescription: () => import('./input-description'),
    },
    mixins: [wfStatusMixin],
    model: {
      prop: 'data',
      event: 'change'
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      procDefKey: { // 参数
        type: String,
        default: ''
      },
      url: {
        type: String,
        default: ''
      },
      formlabelWidth: {
        type: String,
        default: ''
      },
      entity: {
        type: Object,
        default: {
          show: false,
          type: 'build',
          params: {},
        },
      },
      needInit: {
        type: Boolean,
        default: true
      },
      variables: {
        type: Object,
        default: {
          show: false,
          type: 'build',
          params: {},
        },//当出现需要添加其他参数，并且不想在实体类里面添加可传入
      },
    },
    data() {
      return {
        form: {
          isRead:'',
          leaderConfirm:'',
          sendOtherLeader:'',
          description: '',
          selectAssigneeList: []
        },
        isShow:false,
      }
    },
    watch:{
      'form.sendOtherLeader':{
        immediate: true,
        handler: function (val) {
          console.log("-----------------------"+val)
          if((val==''&&this.entity.status==0)||
            this.entity.taskKey=='UserTask_0giw23k'||
            this.entity.taskKey=='UserTask_1ete2q8'||
            this.entity.taskKey=='UserTask_1ete2q8'||
            this.entity.taskKey=='UserTask_1ikrhsb'||
            this.entity.taskKey=='UserTask_1oh6omg'||
            this.entity.taskKey=='UserTask_1ikrhsb'||
            this.entity.taskKey=='UserTask_0ycc27g'||
            this.entity.taskKey=='UserTask_1ete2q8'||
            this.entity.taskKey=='UserTask_0m5jq6b'){
            this.isShow =false
          }else {
            console.log('进入')
            this.isShow = true
            this.$nextTick(()=>{
              if(this.entity.status==0){
                this.variables.sendOtherLeader=this.form.sendOtherLeader+''
              }
              const params = {
                businessId: this.businessId,
                procDefKey: this.procDefKey,
                url: this.url,
                entity: this.entity,
                variables:this.variables
              }
              this.initNodeAttribute(params).then(() => {
                this.$emit('complete', this.wfNode)
              })
            })

          }
        },
        deep: true
      },
      'form.leaderConfirm':{
        immediate: true,
        handler: function (val) {
          console.log("-----------------------"+val)
          if((val==''&&this.entity.status==0)||this.entity.taskKey=='UserTask_0giw23k'||
            this.entity.taskKey=='UserTask_1ete2q8'||
            this.entity.taskKey=='UserTask_1ete2q8'||
            this.entity.taskKey=='UserTask_1ikrhsb'||
            this.entity.taskKey=='UserTask_1oh6omg'||
            this.entity.taskKey=='UserTask_1ikrhsb'||
            this.entity.taskKey=='UserTask_0ycc27g'||
            this.entity.taskKey=='UserTask_1ete2q8'){
            this.isShow =false
            this.wfNode.dueAuto='0'
          }else {
            this.isShow = true
            if(this.entity.taskKey=='UserTask_0m5jq6b'||(this.entity.taskKey=='UserTask_0m5jq6b'&&this.form.leaderConfirm==1)){
              this.variables.leaderConfirm=this.form.leaderConfirm+''
            }
            const params = {
              businessId: this.businessId,
              procDefKey: this.procDefKey,
              url: this.url,
              entity: this.entity,
              variables:this.variables
            }
            this.initNodeAttribute(params).then(() => {
              this.$emit('complete', this.wfNode)
            })
          }
        },
        deep: true
      },
    },
    methods: {
      changeFormValue(val){
        this.form.selectAssigneeList = []
        if(this.$refs.selectAssignee){
          this.$refs.selectAssignee.clearChoose()
        }
      },
      getForm() {
        return this.form
      },
    }
  }
</script>

<style scoped>

</style>
